<?php

declare(strict_types=1);

namespace App\Entities;

use Illuminate\Database\Eloquent\Model;

class OrderModel extends Model
{
    protected $table = 'orders';

    public const ORDER_CLOSED = 1;  // 订单已经关闭

    public const PAYMENT_METHOD_LJSH = 'ljsh';  // 余额抵扣、优惠券使用后，订单金额为 0 的情况，不调用第三方支付接口
    public const PAYMENT_METHOD_WECHAT = 'wechat'; // 支付方式，微信
    public const PAYMENT_METHOD_ALIPAY = 'alipay'; // 支付宝
    public const PAYMENT_METHOD_CASH = 'cash'; // 现金
    public const PAYMENT_METHOD_BANK_TRANSFER = 'bank_transfer'; // 银行转账
    public const PAYMENT_METHOD_DAOWAY = 'daoway'; // 到位平台支付

    public const PAYMENT_METHODS = [
        [
            'key' => self::PAYMENT_METHOD_WECHAT,
            'name' => '微信支付',
        ],
        [
            'key' => self::PAYMENT_METHOD_ALIPAY,
            'name' => '支付宝',
        ],
        [
            'key' => self::PAYMENT_METHOD_BANK_TRANSFER,
            'name' => '银行转账',
        ],
        [
            'key' => self::PAYMENT_METHOD_CASH,
            'name' => '现金',
        ],
    ];

    public const REFUND_STATUS_PENDING = 'pending';
    public const REFUND_STATUS_APPLIED = 'applied';
    public const REFUND_STATUS_PROCESSING = 'processing';
    public const REFUND_STATUS_SUCCESS = 'success';
    public const REFUND_STATUS_FAILED = 'failed';
    public static $refundStatusMap = [
        self::REFUND_STATUS_PENDING => '未退款',
        self::REFUND_STATUS_APPLIED => '已申请退款',
        self::REFUND_STATUS_PROCESSING => '退款中',
        self::REFUND_STATUS_SUCCESS => '退款成功',
        self::REFUND_STATUS_FAILED => '退款失败',
    ];

    public const SHIP_STATUS_DISTRIBUTION = 'distribution';
    public const SHIP_STATUS_PENDING = 'pending';
    public const SHIP_STATUS_DELIVERED = 'delivered';
    public const SHIP_STATUS_SUCCESS = 'success';
    public const SHIP_STATUS_RECEIVED = 'received';
    public static $shipStatusMap = [
        self::SHIP_STATUS_DISTRIBUTION => '待分配',
        self::SHIP_STATUS_PENDING => '待上门', //未上门(已分配待上门)
        self::SHIP_STATUS_DELIVERED => '已上门',
        self::SHIP_STATUS_SUCCESS => '已完成', //已完成(待评价) 只有订单详情页用到了
        self::SHIP_STATUS_RECEIVED => '客户已确认', //userorder received 用到
    ];

    public function product()
    {
        return $this->belongsTo(ProductModel::class);
    }

    public function productSku()
    {
        return $this->belongsTo(ProductSkuModel::class, 'product_sku_id');
    }
}
